﻿<UserControl xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"  x:Class="Candy.Controls.DendoCtrl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:c="clr-namespace:Candy"
    xmlns:ms="clr-namespace:System.Windows.Controls;assembly=System.Windows"
    xmlns:stk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    xmlns:layout="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit"
             xmlns:tlk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
             xmlns:win="clr-namespace:System.Windows;assembly=System.Windows.Controls"
    Width="400" Height="300" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
    <UserControl.Resources>
        <Style x:Key="BorderStyle1" TargetType="Border"/>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" UseLayoutRounding="True" >
        <Grid.Resources>
            <!--<Setter Property="Background" Value="Gray" />-->
            <win:HierarchicalDataTemplate x:Key="DataTemplate1" ItemsSource="{Binding Path=SubNodes}">
                <Grid HorizontalAlignment="Stretch"  Margin="0"  ShowGridLines="False" Height="{Binding Path=Height}" MinWidth="12" d:DesignWidth="185" d:DesignHeight="129" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0.5*" MinWidth="0" />
                        <ColumnDefinition Width="0.5*" MinWidth="0"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Path Margin="0,0,0,-2"  Visibility="{Binding IsNode, Converter={StaticResource VisibilityConverter}}" Height="{Binding Path=Height}" Width="Auto" Grid.RowSpan="2" Grid.ColumnSpan="2" Fill="{x:Null}" Stretch="Fill" Stroke="{StaticResource Foreground}"  VerticalAlignment="Stretch" StrokeThickness="2">
                        <Path.Data>
                            <LineGeometry StartPoint="0,1" EndPoint="0,2" />
                        </Path.Data>
                    </Path>
                    <Path Margin="-2,0,-2,0" Visibility="{Binding IsLeftEdge, ConverterParameter=negate, Converter={StaticResource VisibilityConverter}}"  Grid.RowSpan="2" Height="Auto" Width="Auto" Stretch="Fill" Stroke="{StaticResource Foreground}" Grid.Column="0"  VerticalAlignment="Top" StrokeThickness="2">
                        <Path.Data>
                            <LineGeometry StartPoint="0,1" EndPoint="2,1" />
                        </Path.Data>
                    </Path>
                    <Path Margin="-2,0,0,0" Visibility="{Binding IsRightEdge, ConverterParameter=negate, Converter={StaticResource VisibilityConverter}}"  Grid.RowSpan="2" Height="Auto" Width="Auto" Stretch="Fill" Stroke="{StaticResource Foreground}" Grid.Column="1"  VerticalAlignment="Top" StrokeThickness="2">
                        <Path.Data>
                            <LineGeometry StartPoint="0,1" EndPoint="2,1" />
                        </Path.Data>
                    </Path>
                    <TextBlock Grid.ColumnSpan="2" Text="{Binding Path=Title}" Visibility="{Binding RootLabelVisible, Converter={StaticResource VisibilityConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="NoWrap"  FontSize="11" Style="{StaticResource DefaultLabel}" />
                    <layout:LayoutTransformer Visibility="{Binding Converter={StaticResource VisibilityConverter}, Path=NodeLabelVisible}" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center"  >
                        <layout:LayoutTransformer.LayoutTransform>
                            <RotateTransform Angle="90"/>
                        </layout:LayoutTransformer.LayoutTransform>
                        <TextBlock Text="{Binding Path=Title}" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="NoWrap"   FontSize="10" Style="{StaticResource DefaultLabel}" />
                    </layout:LayoutTransformer>
                    <layout:LayoutTransformer Visibility="{Binding Converter={StaticResource VisibilityConverter}, Path=DistanceLabelVisible}" Grid.ColumnSpan="2" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"  >
                        <layout:LayoutTransformer.LayoutTransform>
                            <RotateTransform Angle="90"/>
                        </layout:LayoutTransformer.LayoutTransform>


                        <Border Background="{StaticResource Foreground}" CornerRadius="1" HorizontalAlignment="Center" VerticalAlignment="Center">
                            <TextBlock Text="{Binding Path=RoundedDistance}" ToolTipService.ToolTip="{Binding Path=Distance}" HorizontalAlignment="Center" VerticalAlignment="Center"  TextWrapping="NoWrap"   FontSize="10" Margin="1,0"  />
                        </Border>
                    </layout:LayoutTransformer>
                    <layout:LayoutTransformer HorizontalAlignment="Center" Grid.ColumnSpan="2" Visibility="{Binding Converter={StaticResource VisibilityConverter}, Path=IsLeafLabel}"  Margin="0,2,0,0" >
                        <layout:LayoutTransformer.LayoutTransform>
                            <RotateTransform Angle="90"/>
                        </layout:LayoutTransformer.LayoutTransform>
                        <Grid>
                            <Grid Visibility="{Binding IsEmpty, Converter={StaticResource VisibilityConverter}}">
                                <TextBlock Text="Gene was deleted" Foreground="Red" FontSize="10"/>
                            </Grid>
                            <Grid Background="Transparent" Visibility="{Binding IsEmpty, ConverterParameter=negate, Converter={StaticResource VisibilityConverter}}">

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                                    <ColumnDefinition Width="*"></ColumnDefinition>
                                    <ColumnDefinition Width="*"></ColumnDefinition>
                                </Grid.ColumnDefinitions>
                                <tlk:ContextMenuService.ContextMenu >
                                    <tlk:ContextMenu DataContext="{Binding Source={StaticResource Locator}}" >
                                        <tlk:MenuItem Header="Edit" Command="{Binding Genes.EditGene, Mode=OneWay}"  />
                                        <tlk:MenuItem Header="Delete" Command="{Binding Genes.DeleteGenes, Mode=OneWay}"/>
                                        <tlk:Separator HorizontalAlignment="Stretch"/>
                                        <tlk:MenuItem Header="Move" Command="{Binding Genes.MoveSelectedGenes, Mode=OneWay}"/>
                                        <tlk:MenuItem Header="Copy As FastA" Command="{Binding Genes.CopyAsFasta, Mode=OneWay}"/>
                                        <tlk:Separator HorizontalAlignment="Stretch"/>
                                        <tlk:MenuItem Header="Blast" CommandParameter="{Binding Genes.SelectedGenes, Converter={StaticResource GeneListConverter}, Mode=OneWay}" Command="{Binding JobManager.BlastSecondaryBaits, Mode=OneWay, Source={StaticResource Locator}}" />
                                    </tlk:ContextMenu>
                                </tlk:ContextMenuService.ContextMenu>
                                <!--<Button Click="OnDeleteGene"  Grid.Column="2" FontSize="10" Style="{StaticResource DefaultButton}" >
                                    <StackPanel Orientation="Horizontal" >
                                        <Image Source="Images/DeleteHs.png"/>

                                    </StackPanel>
                                </Button>-->
                                <Button   Grid.Column="1" FontSize="10" Style="{StaticResource DefaultButton}" >
                                    <StackPanel Orientation="Horizontal" >
                                        <TextBlock Margin="0,0,2,0" FontWeight="Bold" Text="{Binding Item, Converter={StaticResource Gene2LabelConverter}}" Foreground="{Binding Item, Converter={StaticResource Gene2ColorConverter}, Mode=OneWay}" />
                                        <!--"{Binding Path=Item, Mode=OneWay,Converter={StaticResource gene2ColorConverter}}"-->
                                        <TextBlock Margin="0,0,2,0" Text="{Binding Item.Name}" FontSize="10" Style="{StaticResource DefaultLabel}" />

                                        <!--<TextBlock Text="{Binding Item.Genotype.Id}" Foreground="Black" FontSize="10"/>-->

                                    </StackPanel>
                                </Button>
                                <Border Grid.Column="1" Visibility="{Binding IsSelected, Converter={StaticResource VisibilityConverter}}" BorderBrush="{StaticResource Accent}" BorderThickness="2,1" CornerRadius="0">
                                    <!--<Border.Effect>
                                        <BlurEffect Radius="2"/>
                                    </Border.Effect>-->
                                </Border>
                                <!--<Ellipse Visibility="{Binding IsSelected, Converter={StaticResource VisibilityConverter}}"  Fill="#FF008CFF" Stroke="#FF96CFFE" HorizontalAlignment="Center" Margin="0" Width="10" Height="10" VerticalAlignment="Center">
                                    <Ellipse.Effect>
                                        <BlurEffect Radius="4"/>
                                    </Ellipse.Effect>
                                </Ellipse>-->
                            </Grid>
                        </Grid>
                    </layout:LayoutTransformer>

                </Grid>
            </win:HierarchicalDataTemplate>

            <!-- Put all the items inside a horizontally stacked panel -->
            <ItemsPanelTemplate x:Key="ItemsPanel">
                <StackPanel Orientation="Horizontal" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0,0,0,0" />
            </ItemsPanelTemplate>

            <!-- TreeViewItem style to stack a header on top of children -->
            <Style x:Key="ContainerStyle" TargetType="controls:TreeViewItem">
                <Setter Property="ItemsPanel" Value="{StaticResource ItemsPanel}" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="controls:TreeViewItem">
                            <StackPanel Orientation="Vertical" x:Name="Root" VerticalAlignment="Top" HorizontalAlignment="Stretch">

                                <ContentControl 
									x:Name="HeaderContent" 
									Content="{TemplateBinding Header}" 
									ContentTemplate="{TemplateBinding HeaderTemplate}" 
									HorizontalAlignment="Stretch"
									HorizontalContentAlignment="Stretch"
									VerticalAlignment="Center"/>

                                <ItemsPresenter 
									x:Name="Items" 
									VerticalAlignment="Top"
									HorizontalAlignment="Center" />

                            </StackPanel>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>


        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" MinWidth="103"/>
            <ColumnDefinition Width="Auto" MinWidth="88"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" MinHeight="34"/>
            <RowDefinition Height="Auto" MinHeight="25"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Border Margin="2,2,2,2" CornerRadius="4,4,4,4" Background="{StaticResource ControlBackground}" Grid.ColumnSpan="3" Grid.RowSpan="2"/>

        <ms:ScrollViewer Grid.Row="2"  VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Grid.ColumnSpan="3">
            <layout:LayoutTransformer x:Name="Transformer" HorizontalAlignment="Left" VerticalAlignment="Top">
                <layout:LayoutTransformer.LayoutTransform>
                    <RotateTransform x:Name="Rotation" Angle="-90"/>
                </layout:LayoutTransformer.LayoutTransform>
                <!--<c:LeftRotatePanel  ms:ScrollViewer.VerticalScrollBarVisibility="Auto" ms:ScrollViewer.HorizontalScrollBarVisibility="Auto" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2,2,0,0">-->
                <controls:TreeView  ItemsSource="{Binding Path=Tree}" x:Name="DendoTree"	ItemsPanel="{StaticResource ItemsPanel}"  ItemContainerStyle="{StaticResource ContainerStyle}" ItemTemplate="{StaticResource DataTemplate1}" Height="Auto" VerticalAlignment="Stretch"  HorizontalAlignment="Stretch" Background="{StaticResource ControlBackground}" BorderThickness="0,0,0,0"   ms:ScrollViewer.VerticalScrollBarVisibility="Disabled" ms:ScrollViewer.HorizontalScrollBarVisibility="Disabled"  />
            </layout:LayoutTransformer>
            <!--</c:LeftRotatePanel>-->
        </ms:ScrollViewer>
        <Slider x:Name="ScaleSlider" Value="{Binding Mode=TwoWay, Path=ScaleFactor}" Height="Auto" HorizontalAlignment="Stretch" Margin="49,4,8,8" Width="Auto"  Maximum="600" ToolTipService.ToolTip="ScaleFacor" SmallChange="1" LargeChange="10" Minimum="1" Grid.ColumnSpan="3" Grid.Row="1" d:LayoutOverrides="Height" VerticalAlignment="Center" />
        <ToggleButton x:Name="ToggleLabels" IsChecked="{Binding Mode=TwoWay, Path=ShowDistanceLabel}" Height="Auto" Margin="8,8,2,4" VerticalAlignment="Center" Content="Show Distances"  HorizontalAlignment="Left"/>
        <RadioButton Height="Auto" Margin="4,10,8,4" Content="Vertical"  GroupName="Layout" Grid.Column="2" Width="Auto" HorizontalAlignment="Left" d:LayoutOverrides="Height" VerticalAlignment="Center"/>
        <TextBlock HorizontalAlignment="Left" Margin="8,4,0,8" Width="37" Text="Scale" TextWrapping="Wrap" Grid.Row="1"/>
        <RadioButton  x:Name="HorizontalRadio" IsChecked="True"  Height="Auto" Margin="4,10,8,4"  Content="Horizontal" GroupName="Layout" d:LayoutOverrides="Height" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" />

    </Grid>

</UserControl>
